﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static Tools.FileOperator;

namespace Tools.SMTP
{
    public static class SMTPWarnContent
    {
        public static string CreateWarnContent(CsvFileReturnAllListV2 csvFileReturnAllListV2,string vehicle,int accerrorvalue)
        {
            string errormessage = "";
            var latiserror=csvFileReturnAllListV2.Lat.Any(a=>a==-100);
            if (latiserror)
            {
                errormessage += $"{vehicle}的{csvFileReturnAllListV2.name}文件中的Lat出现了-100问题\n";
            }
            var loniserror = csvFileReturnAllListV2.Lon.Any(a => a == -100);
            if (loniserror)
            {
                errormessage += $"{vehicle}的{csvFileReturnAllListV2.name}文件中的Lon出现了-100问题\n";
            }
            var chan = csvFileReturnAllListV2.otherchannels;
            var channame=csvFileReturnAllListV2.channelorderlist;
            for (int i = 0; i < chan.Count; i++)
            {
               var chaniserror1=chan[i].All(a => a == -1);
                if (chaniserror1)
                {
                    errormessage += $"{vehicle}的{csvFileReturnAllListV2.name}文件中的{channame[i]}出现了-1问题\n";
                }
                var chaniserror2 = chan[i].All(a => a == -3);
                if (chaniserror2)
                {
                    errormessage += $"{vehicle}的{csvFileReturnAllListV2.name}文件中的{channame[i]}出现了-3问题\n";
                }
                if (chan[i].Any(a => a > 10) && channame[i].ToLower().Contains("acc") && channame[i].ToLower().Contains("st"))
                {
                    errormessage += $"{vehicle}的{csvFileReturnAllListV2.name}文件中的{channame[i]}出现了{accerrorvalue}g\n";
                }
                if (chan[i].Any(a => a > accerrorvalue) && channame[i].ToLower().Contains("whl") && channame[i].ToLower().Contains("acc")){
                    errormessage += $"{vehicle}的{csvFileReturnAllListV2.name}文件中的{channame[i]}出现了{accerrorvalue}g\n";
                }
            }
            return errormessage;
        }


        public static bool IsPastOneHour(DateTime startTime,int timespan)
        {
            // 获取当前时间
            DateTime currentTime = DateTime.Now;

            // 计算时间间隔
            TimeSpan timeElapsed = currentTime - startTime;

            // 判断是否过了1小时
            if (timeElapsed.TotalMinutes >= timespan)
            {
                return true;
            }

            return false;
        }

    }
}
